VC++,how to expnding certain node in tree control

Started by
3 comments, last by akira32 15 years, 8 months ago
VC++,how to expnding certain node in tree control(not using TVN_ITEMEXPANDING)? I just know the path in tree control I want to expand.
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
Advertisement
Uh, TVM_EXPAND? All you need is the handle to the item, which you may or may not have, but that depends on what exactly you're doing. You can always enumerate nodes with TVM_GETNEXTITEM.
Million-to-one chances occur nine times out of ten!
Quote:Original post by Mike nl
Uh, TVM_EXPAND? All you need is the handle to the item, which you may or may not have, but that depends on what exactly you're doing. You can always enumerate nodes with TVM_GETNEXTITEM.


Tank you,Mike. But I have a problem how do I know the value hItem?
I just know the path (in TreeControl) I want to expand (such as A/B/C).
I do not know how to get the hItem of "A/B/C"

akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
Like I said, use TVM_GETNEXTITEM to enumerate the children (flag = TVGN_CHILD) of a node.

This might work. I haven't tested or even tried to compile it, but this might give you an idea.
HTREEITEM GetTreeItemByPath(HWND hTree, HTREEITEM hNode, string path){    // Strip the first segment off the path    string::size_type pos = path.find_first_of("\\/");    const string name = path.substr(0, pos);    if (pos == string::npos) {        path.clear();    } else {        path.erase(0, pos + 1);    }    // Only the first 260 chars matter    TCHAR buffer[260];    TVITEM item;    item.mask       = TVIF_TEXT;    item.pszText    = buffer;    item.cchTextMax = 260;    // Enumerate the children of the node    item.hItem = TreeView_GetChild(hTree, hNode);    while (item.hItem != NULL)    {        // Get the item's text        TreeView_GetItem(hTree, &item);        // Compare it        if (name == buffer) {            // Match, find the rest of the path            HREEITEM hItem = GetTreeItemByPath(hTree, item.hItem, path);            // If duplicates are not possible, you can just return hItem immediately instead of continuing the search.            if (hItem != NULL) {                return hItem;            }        }        item.hItem = TreeView_GetNextSibling(hTree, item.hItem);    }    return NULL;}HTREEITEM GetTreeItemByPath(HWND hTree, const string& path){    return GetTreeItemByPath(hTree, TreeView_GetRoot(hTree), path)}


[Edited by - Mike nl on August 20, 2008 5:09:19 AM]
Million-to-one chances occur nine times out of ten!
Mike nl,thank you! I had solved it.

akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32

This topic is closed to new replies.

Advertisement